﻿<?php
$inc_lib = realpath(dirname(__FILE__) . '/../../teia.lib/inc/inc_core.inc');
require_once $inc_lib;
use teia\webdev\php\core as teia;

$inc_cust = realpath(dirname(__FILE__) . '/../inc/inc_cust.inc');
require_once $inc_cust;
use teia\webdev\php\cust as cust;

$result = teia\SessionWrapper::start();

if (!$result) {
	echo "Session Error: Failed to start session\n";
}

$err_msg = isset($_REQUEST['err_msg']) ? $_REQUEST['err_msg'] : '';
if (!isset($page_title)) $page_title = 'Shoes Boutique: Catalog';

try {
	$filter = teia\ProductCatalog::process_filter_form();
	if (isset($prod_gender)) $filter['prod_filter']['prod_gender'] = $prod_gender;
	if (isset($_REQUEST['prod_type']) && is_string($_REQUEST['prod_type'])) {
		$filter['prod_filter']['prod_type'] = $_REQUEST['prod_type'];;
	}
	
	// fetch products from database
	$product_listing = new teia\ProductCatalog('_product_catalog_', 'ProductCatalog', null, $filter);
	$paginator = new teia\PaginationProvider('_pagination_', 'Pagination', null, $product_listing);
	$paginator->show_nav(false);
} catch (InvalidArgumentException $e) {
	$err_msg = $e->getMessage() . ' [' . $e->getCode() . ']';
} catch (Exception $e) {
	$err_msg = $e->getMessage() . ' [' . $e->getCode() . ']';
}
?>

<!DOCTYPE html>
<html>
	<head>
		<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
		<title><?php echo $page_title; ?></title>
		<link href="/style/layout.css" rel="stylesheet" type="text/css">
		<link href="/style/style01.css" rel="stylesheet" type="text/css">
		<link href="/style/style_slideshow.css" rel="stylesheet" type="text/css">
		<link href="/style/catalog.css" rel="stylesheet" type="text/css">
		<?php teia\FunctionPool::include_jquery(); ?>
		<script src="/script/script.js"></script>
		<script src="/script/autoadvance.js"></script>
	</head>
	<body>
		<div align="center" style="position: absolute; margin-left: inherit; margin-right: inherit">
			<!-- Display header logo -->
			<?php cust\CustFunctions::display_header_logo(); ?>
			<!-- Display top navigation -->
			<?php cust\CustFunctions::display_top_nav(); ?>
			<!-- Display menu -->	
			<?php cust\CustFunctions::display_menu(); ?>
			<!-- Display ad-banner-->
			<?php cust\CustFunctions::display_top_banner(); ?>
			<!-- Display gender sub-menu-->
			<?php cust\CustFunctions::display_gender_submenu(); ?>
			<br />
			<div id="container_slideshow">
				<!-- Display slide show -->
				<div id="slideshow">
					<ul class="slides">
				<?php
					$all_slides = $product_listing->get_all_slides(); 
					foreach ($all_slides as $slide) {
						echo "<li>$slide</li>\n";
					}
				?> 
					</ul>
					<span class="arrow previous"></span>
					<span class="arrow next"></span>
				</div>
    			<?php @$paginator->display('page'); ?>
			</div>
			<br />
			<br />
			<?php cust\CustFunctions::display_footer(); ?>
		</div>
	</body>
</html>
